﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using UCS.XNA.Utils;
using UCS.XNA.Utils.Geometries;

namespace DivideAndConquer.States.InGame
{
    public class Wall
    {
        #region Attributes and Properties

        private WallOrientation _orientation;
        public WallOrientation Orientation
        {
            get { return _orientation; }
        }

        private WallSegment _segmentA;
        public WallSegment SegmentA
        {
            get { return _segmentA; }
            set { _segmentA = value; }
        }

        private WallSegment _segmentB;
        public WallSegment SegmentB
        {
            get { return _segmentB; }
            set { _segmentB = value; }
        }

        private Vector2 _position;
        public Vector2 Position
        {
            get { return _position; }
            set { _position = value; }
        }

        #endregion

        #region Constructors

        public Wall(Vector2 position, WallOrientation orientation)
        {
            _position = position;
            _orientation = orientation;

            this.InitializeSegments();
        }

        #endregion

        #region Private Methods

        private void InitializeSegments()
        {
            WallGrowDirection growDirectionA = _orientation == WallOrientation.Horizontal ? WallGrowDirection.Left : WallGrowDirection.Top;
            WallGrowDirection growDirectionB = _orientation == WallOrientation.Horizontal ? WallGrowDirection.Right : WallGrowDirection.Bottom;

            _segmentA = new WallSegment(_position, growDirectionA);
            _segmentB = new WallSegment(_position, growDirectionB);
        }

        #endregion

        #region Public Methods

        public void Update(GameTime gameTime)
        {
            _segmentA.Update(gameTime);
            _segmentB.Update(gameTime);
        }

        public void Draw(GameTime gameTime)
        {
            _segmentA.Draw(gameTime);
            _segmentB.Draw(gameTime);
        }

        #endregion
    }
}